package com.isoft.c2team3service2.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.c2team3service2.entity.User;
import com.isoft.c2team3service2.entity.UserDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Update("update tb_login set password=#{password} ,salt=#{salt} where email=#{email}")
    int updatePassword(String email, String password, String salt);

    @Insert("insert into tb_login (email, password,salt,role_id) values (#{email}, #{password},#{salt} , #{role_id})")
    int addUser(String email, String password, String salt ,@Param("role_id") Integer roleId);
    // 在UserMapper中
    @Select("SELECT id, email, password, salt, nick_name, user_name, photourl FROM user WHERE id = #{id}")
    UserDTO selectUserDTOById(Integer id);
    /**
     * 查询用户的角色ID
     */
//    @Select("SELECT role_id FROM user_role  where user_id=#{userId}")
//    Integer selectUserRoleId(Integer userId);

    @Select("SELECT * FROM tb_person where id = #{userId}")
    List<User> selectUserDetail(Integer userId);
      /* * 根据用户ID查询：用户昵称、用户类型、艺人名称（艺人专属）
            * @param targetUserId 被查询用户ID
     * @return 封装结果：nickName, userType, artistName
     */
    @Select("""
        SELECT 
            u.nick_name AS nickName, 
            u.user_type AS userType, 
            a.name AS artistName 
        FROM tb_login u
        LEFT JOIN artist a ON u.artist_id = a.id  -- 艺人关联（普通用户为NULL）
        WHERE u.id = #{targetUserId}
    """)
    Map<String, Object> selectUserNickAndArtistName(Integer targetUserId);

    @Select("SELECT id from tb_login WHERE email = #{email}")
    Integer selectId(@Param("email") String email);
}
